package com.ykdl.member.kid.messagebox;

import java.util.HashMap;
import java.util.Map;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

import com.ykdl.member.kid.R;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.adapters.MyReanswerListAdapter;
import com.ykdl.member.kid.beans.MessageBean;
import com.ykdl.member.kid.beans.SystemMessageListBean;
import com.ykdl.member.kid.beans.TopicAndPostBean;
import com.ykdl.member.kid.beans.TopicAndPostListBean;
import com.ykdl.member.kid.circle.TopicAndResultActivity;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.image.ImageLoader;
import com.ykdl.member.kid.messagebox.MyMessageAcivity1.getSystemMessageTag;
import com.ykdl.member.kid.util.AccessTokenKeeper;
import com.ykdl.member.kid.widget.RefreshListView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

public class MyReanswerListActivity extends BaseScreen{
	private MyReanswerListAdapter adapter;
	private RefreshListView reanswer_list;
	private String TAG = "MyReanswerListActivity";
	private String parent_post_actor_id ;
	private AccessTokenKeeper mAccessTokenKepper ;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTopTitle("收到的回复", 0, R.drawable.reg_closebt, new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.e("ssss","setResultode---`11");
				setResult(-1);
				finish();
			}
		}, 0, 0, null, R.drawable.title_bg, false);
		setContent(R.layout.myreanswerlistactivity_xml);
		parent_post_actor_id = getIntent().getStringExtra("parent_post_actor_id");
		mAccessTokenKepper = new AccessTokenKeeper(this);
		inint();
		}
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		Log.e("ssss","setResultode---`11");
		setResult(-1);
		super.onBackPressed();
	}
	public void inint() {
		adapter = new MyReanswerListAdapter(this,TAG);
		reanswer_list = (RefreshListView)findViewById(R.id.reanswer_list);
		reanswer_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				TopicAndPostBean bean= (TopicAndPostBean)adapter.getItem(arg2);
				Intent intent = new Intent(mContext, TopicAndResultActivity.class);
				intent.putExtra(TopicAndResultActivity.STR_TOPIC_ID, bean.getTopic_id()+"");
				intent.putExtra(TopicAndResultActivity.STR_GROUP_ID, bean.getSource_id()+"");
				intent.putExtra(TopicAndResultActivity.STR_POST_ID, bean.getPost_id()+"");
				startActivity(intent);
			}
		});
		getPostList();
	}
	public void getPostList() {
		showProgress("正在加载中,请稍等...");
		String  pageurl =KidConfig.GET_POSTS_LIST;
		Map<String,String> map = new HashMap<String, String>();
		map.put("parent_post_actor_id", mAccessTokenKepper.getMactor_id());
		map.put("post_actor_id", parent_post_actor_id);
		HttpBaseRequest request  =  Wxxr.getInstance().getRequest(pageurl, map,"");
		TaskManager.startHttpRequest(request, new getPostListTag(),  TopicAndPostListBean.class);
	}
	
	class getPostListTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof TopicAndPostListBean) {
				TopicAndPostListBean bean = (TopicAndPostListBean)t;
				Toast.makeText(mContext, "加载成功", 1).show();
				adapter.setlist(bean.getList());
				reanswer_list.setAdapter(adapter);
				adapter.notifyDataSetChanged();
				reanswer_list.setMoreButtoIsGon(true);
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	protected void onResume() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().setCurrentActivity(TAG);
		super.onResume();
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().pause(TAG);
		super.onPause();
	}
}
